package jmind.asteroidea.core;

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;

import java.util.Set;

/**
 * description: 扫描工具类
 *
 * @author weibo.xie
 * @date:2022/7/7 上午11:01
 */
public class ClassFileScanner {
    private String packagePath;

    private Reflections reflections;

    public ClassFileScanner(String packagePath) {
        this.packagePath = packagePath;

        this.reflections = new Reflections(new ConfigurationBuilder()
                .addUrls(ClasspathHelper.forPackage(this.packagePath))
                .setScanners(new TypeAnnotationsScanner(),new SubTypesScanner())
        );
    }

    public Set<Class> getTypesAnnotatedWith(Class annoClass) {
        return reflections.getTypesAnnotatedWith(annoClass);
    }

    public Set<Class> getSubTypesOf(Class parentClass) {
        return reflections.getSubTypesOf(parentClass);
    }

}

